#ifndef TABU_SEARCH_H
#define TABU_SEARCH_H

#include "substract_network.h"
#include "virtual_network.h"
#include <algorithm>
#include <map>
//#include <cstdlib>

struct solution{
	int viable;
	int edges;
	struct Node** node_map;
	list<int>** paths;
};

int compareSolutions( const void* s1, const void* s2 ){
	if( ((struct solution*)s1)->viable != ((struct solution*)s2)->viable )
		return ((struct solution*)s2)->viable - ((struct solution*)s1)->viable;
	else{
		return( ((struct solution*)s1)->edges - ((struct solution*)s2)->edges );
	}	 
}

class TabuSearchHeuristic{
	public:
		TabuSearchHeuristic( SubstractNetwork*, VirtualNetwork* );
		~TabuSearchHeuristic();
		
		bool solve();
		void copySolution( struct Node*, Edge*** );
		
	private:
		map<unsigned int,unsigned int> TABU;
		
		struct solution current_solution;
		struct solution best_solution;
		
		void initialize();
		void getInitialSolution();
		
		int buildPath( int, int, list<int>**, int );
		void calculateNeighborhood( struct solution* s, int );
		
		SubstractNetwork* sn;
		VirtualNetwork* vn;
		
		int num_changes;
		int tenure;
		int iterations;
		
		struct Node* vn_nodes;
		struct Node* sn_nodes;
		
		int* choices;
		bool viable;
		
		int sn_m;
		int sn_n;
		
		int vn_m;
		int vn_n;
		
		
};

#include "tabu_search.cpp"



#endif


